//===COMMENT===

package bubble3d.animation {

	import bubble3d.model.Vertex;
	import bubble3d.rendering.Engine;
	import bubble3d.main.World3D;
	import bubble3d.core3d.Object3D;
	import bubble3d.math.Calculations;

	public class Rotation extends Animation {
	
		private var decay:Number = 1;
	
		private var rX:Number;
		private var rY:Number;
		private var rZ:Number;
	
		private var momentumX:Number = 0;	
		private var momentumY:Number = 0;
		private var momentumZ:Number = 0;
	
		public function Rotation(object3D:Object3D, rX:Number, rY:Number, rZ:Number, frames:Number, decay:Number){
			
			initAnimation(object3D);
			trace("Rotation started for "+object3D.getId());
			totalFrames = frames;
			decay = decay;
		
			momentumX = decay*rX;
			momentumY = decay*rY;
			momentumZ = decay*rZ;
		}

		public override function animate():void {
			currentFrame++;
			
			if(momentumY != 0) {
				object3D.rotateCenterY(momentumY);
			}
			if(momentumX != 0) {
				object3D.rotateCenterX(momentumX);
			}
			if(momentumZ != 0) {
				object3D.rotateCenterZ(momentumZ);				
			}

			momentumY = decay*momentumY;
			momentumX = decay*momentumX;
			momentumZ = decay*momentumZ;
			
			if(currentFrame >= totalFrames) {
				completeAnimation();
			}
		}
	}

}